﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UnknowError : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userName"] == null || Session["roleID"] == null)
        {
            Response.Redirect("Login.aspx");
            Response.End();
        }
        if (!IsPostBack)
        {
            Exception ex = Server.GetLastError().GetBaseException();
            string exContent = "";
            if (ex != null)
            {
                // 错误的信息
                exContent += "<span style='color:red;'>错误的信息:</span>" + ex.Message + "<br/>";
                // 错误的堆栈
                exContent += "<span style='color:red;'>错误的堆栈:</span>" + ex.StackTrace.Replace(" ", "<br/>")+"<br/>";
                // 出错的方法名
                exContent += "<span style='color:red;'>出错的方法名:</span>" + ex.TargetSite.Name + "<br/>";
                // 出错的类名
                exContent += "<span style='color:red;'>出错的类名:</span>" + ex.TargetSite.DeclaringType.FullName;
                Log newLog = new Log();
                newLog.Title = "系统性错误！";
                newLog.Content = exContent;
                newLog.UserName = Session["userName"].ToString();
                newLog.AddDate = DateTime.Now;
                newLog.Status = "1";
                newLog.AddLog();
            }
            // 清空最后的错误
            Server.ClearError();
        }
    }

}
